package prevote;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.List;

public class PreVotePanel extends javax.swing.JPanel {

	public String infoText = "";
	
    public void addSubmitButtonActionListener(ActionListener l){
    	submitButton.addActionListener(l);
    }
    
    public void setInfoText(String text){
    	infoText += text;
    	infoTextLabel.setText("<html>" + infoText + "</html>");
    }
    
    public String getSecretCodeText(){
    	return secretCodeField.getText();
    }
	
    /** Creates new form PreVotePanel */
    public PreVotePanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        submitButton = new javax.swing.JButton();
        secretCodeField = new javax.swing.JTextField();
        infoTextLabel = new javax.swing.JLabel();

        jLabel1.setText("Please type in your secret code:");

        submitButton.setText("Submit");
        submitButton.setEnabled(false);
        
        secretCodeField.addKeyListener(new java.awt.event.KeyAdapter() {
        	public void keyReleased(java.awt.event.KeyEvent evt) {
                secretCodeFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(secretCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(submitButton)))
                    .addComponent(infoTextLabel))
                .addContainerGap(184, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(secretCodeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(submitButton))
                .addGap(18, 18, 18)
                .addComponent(infoTextLabel)
                .addContainerGap(212, Short.MAX_VALUE))
        );
    }// </editor-fold>

    private void secretCodeFieldActionPerformed(java.awt.event.KeyEvent evt) {
    	if (secretCodeField.getText().length() > 8){
    		submitButton.setEnabled(true);
    	}
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel infoTextLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField secretCodeField;
    private javax.swing.JButton submitButton;
    // End of variables declaration
}